class Converter(object):
    @staticmethod
    def to_ascii(h):
        list_s = []
        for i in range(0, len(h), 2):
            list_s.append(chr(int(h[i:i+2], 16)))
        return ''.join(list_s)
 
    @staticmethod
    def to_hex(s):
        list_h = []
        for c in s:
            list_h.append(str(hex(ord(c))[2:]))
        return ''.join(list_h)


if __name__ == "__main__":
    # print(Converter.to_hex("Hello World!"))
    # print(Converter.to_ascii("48656c6c6f20576f726c6421"))
    
    # 等宽为2的16进制字符串列表也可以如下表示
    # import textwrap
    # s = "48656c6c6f20576f726c6421"
    # res = textwrap.fill(s, width=2)
    # print(res.split())  #['48', '65', '6c', '6c', '6f', '20', '57', '6f', '72', '6c', '64', '21']

    test = [170, 9, 48, 1, 76, 66, 48, 48, 48, 49, 223, 172]
    for i in range(4, 10):
        print('i=', i)
        print('原值：',test[i], 'assic:', chr(test[i]))